import json
import requests
import threading
import zlib
from .func import *

class Roller(threading.Thread):
    def __init__(self,date,queue,):
        threading.Thread.__init__(self)
        self.queue = queue
        self.url = 'http://roll.kuaiyudian.com/roll-download/'+date
        self.running = False

    def run(self):
        if self.running:
            raise 'aready running'
        self.running = True
        r = requests.get(self.url, stream=True)
        for line in r.iter_lines():
            # filter out keep-alive new lines
            if line:
                try:
                    l = line.decode('utf-8','ignore')
                    self.queue.put(l)
                except:
                    pass